package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("permissionstatus")
public class PermissionstatusController {
    @DubboReference
    private PermissionService permissionService;

    @GetMapping("findPage")
    public Result findPage(QueryPageBean queryPageBean) {
        PageResult pageResult = permissionService.findPage(queryPageBean);
        return new Result(true, MessageConst.ACTION_SUCCESS, pageResult);
    }

    @GetMapping("findById")
    public Result findById(Integer id) {
        Permission permission = permissionService.findById(id);
        return new Result(true, MessageConst.ACTION_SUCCESS, permission);
    }

    @PostMapping("edit")
    public Result edit(@RequestBody Permission permission) {
        permissionService.edit(permission);
        return new Result(true, MessageConst.ACTION_SUCCESS);

    }

    @PostMapping("delete")
    public Result delete(Integer id) {
        permissionService.delete(id);
        return new Result(true, MessageConst.ACTION_SUCCESS);
    }

    @PostMapping("add")
    public Result add(@RequestBody Permission permission) {
        permissionService.add(permission);
        return new Result(true, MessageConst.ACTION_SUCCESS);
    }

    @GetMapping("findAll")
    public Result findAll() {
        List<Permission> permissionList = permissionService.findAll();
        return new Result(true, MessageConst.ACTION_SUCCESS, permissionList);
    }

}
